/*********************************************************************************
 *       Filename:  proc.c
 *    Description:  
 *
 *        Version:  1.0.0(2024/12/02 18:18:26)
 *         Author:  Zhang Long <1318085470@qq.com>
 *      ChangeLog:  1, Release initial version on "2024/12/02 18:18:26"
 ********************************************************************************/
#include <signal.h>

#include "logger.h"
#include "proc.h"

int		g_sigstop = 0;

void signal_handler(int signum)
{
	switch (signum)
	{
		case SIGTERM:
			log_warn("SIGTERM - stopping\n");
			g_sigstop = 1;
			break;

		case SIGINT:
			log_warn("SIGINT - stopping\n");
			g_sigstop = 1;
			break;

		case SIGPIPE:
			log_warn("SIGPIPE - stopping\n");
			break;

		default:
			break;
	}
}

void install_signal(void)
{
	struct sigaction 	sigact;

	sigemptyset(&sigact.sa_mask);
	sigact.sa_flags = 0;
	sigact.sa_handler = signal_handler;

	sigaction(SIGTERM, &sigact, 0);
	sigaction(SIGINT,  &sigact, 0);
	sigaction(SIGPIPE, &sigact, 0);

	log_debug("Install signal ok\n");
}

/* ----- #ifndef _PROC_H_  ----- */
